<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019.06.05
  Time: 上午 09:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>Login</title>
    <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script type="text/javascript">
        function testJson() {
            var username=$("#username").val();
            var password=$("#password").val();
            $.ajax({
                url:"${pageContext.request.contextPath}/testJson",
                type:"post",
                data:JSON.stringify({username:username,password:password}),
                contentType:"application/json;charset=UTF-8",
                dataType:"json",
                success:function (data) {
                    if (data!=null){
                        alert("您输入的用户名为:"+data.username+"  密码为:"+data.password);
                    }else {
                        alert("null");
                    }
                }
            });
        }
    </script>
  </head>
  <body>
      <form>
        用户名:<input type="text" name="username" id="username"/><br/>
        密&nbsp;&nbsp;码:<input type="password" name="password" id="password"/><br>
        <input type="button" value="测试JSON交互" onclick=" testJson()"/>
      </form>
  </body>
</html>
